<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>景点订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">订单列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">

                       <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                          <div class="layui-input-block">
                                <select name="order_sn" lay-verify="" lay-search id="orderSn_">
                                    <option value="">请选择</option>
                                    {foreach $res as $k=>$v}
                                    <option value="{$v['order_sn']}">{$v['order_sn']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div> 
                        <div class="layui-inline">
                            <label class="layui-form-label">下单时间</label>
                            <div class="layui-input-inline" style="width: 190px;">
                                <input type="text" class="layui-input" id="selectdate" readonly="" placeholder="~">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>

                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="showDetail">详细信息</a>
                      <!--   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="solved">待解决</a> -->
                          {{# if(d.complain_status==0){ }}
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="solved">待解决</a>
                        {{# }else if(d.complain_status==1){ }}
                        <a class="layui-btn layui-btn-xs">已解决</a>

                        {{# } else if(d.complain_status==2){ }}
                        <a class="layui-btn layui-btn-danger layui-btn-xs">未解决</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<!--添加弹窗-->
<div id="hotelOrderInfo" style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group"> 
   <div class="layui-form-item"> 
            <div class="layui-inline">
                <label class="layui-form-label">投诉人：</label>
                <div class="layui-input-block">
                    <input type="text"  id="nickname" autocomplete="off" class="layui-input">
                </div>
            </div>
           
            <div class="layui-inline">
                <label class="layui-form-label">投诉人联系方式：</label>
                <div class="layui-input-block">
                    <input type="text" id="phone" autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>
        <div class="layui-form-item"> 
            <div class="layui-inline">
                <label class="layui-form-label">订单编号：</label>
                <div class="layui-input-block">
                    <input type="text"  id="order_sn" autocomplete="off" class="layui-input">
                </div>
            </div>
           
            <div class="layui-inline">
                <label class="layui-form-label">投诉类型：</label>
                <div class="layui-input-block">
                    <input type="text" id="object_type" autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>
      <div class="layui-form-item">  
          <div class="layui-inline">
                <label class="layui-form-label">投诉图片：</label>
               <div class="layui-input-block" id="complain_annex">  
                </div>
            </div> 
              <div class="layui-inline">
                <label class="layui-form-label">投诉时间：</label>
                <div class="layui-input-block">
                    <input type="text" id="create_time" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>  
         <div class="layui-form-item">   
                <div class="layui-inline">
                <label class="layui-form-label">投诉内容：</label>
                <div class="layui-input-block"> 
                    <textarea id="complain_content" style='width: 250px;height:50px;'>
                        
                    </textarea>
                </div>
            </div> 
        </div>   
    </form>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        laydate.render({
            elem: '#selectdate'
            , range: '~'
        });

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('OrderComplains/Ordercomplains')}"
            ,height: 'full-155'
            ,cols: [[
                 {field:'order_sn',align:'center',title: '订单编号'}
                ,{field:'nickname', align:'center', title: '投诉方'}
                ,{field:'complain_content', align:'center', title: '投诉原因'}
                ,{field:'create_time',width:180, align:'center', title: '投诉时间'}
                ,{field:'complain_status', align:'center', title: '投诉状态',templet:function(d){ 
                    if (d.complain_status == 0){
                        return '新投诉';
                    }else if(d.complain_status == 1){
                        return '已解决';
                    }else if(d.complain_status == 2){
                        return '未解决';
                    }  
                }}
               ,{align:'center',width:150, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:20
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });

        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showDetail'){ 

                   var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var order_id = data.order_id; 
                $.ajax({
                    url: "{:url('OrderComplains/getOrdercomplainsInfo')}",
                    type: 'post',
                    dataType: 'json',
                    data: {order_id:order_id},
                    success: function(data){
                        layer.close(loading); 
                        if (data.code === 0) {  
                            var obj = data.data; 
                            if(obj.order_sn==""){
                                $('#order_sn').val('未设置');
                            }else{
                                $('#order_sn').val(obj.order_sn);
                            }
                             if(obj.pay_type ==""){
                                $('#nickname').val('未设置');
                            }else{
                                $('#nickname').val(obj.nickname);
                            } 
                             $('#complain_content').val(obj.complain_content);
                             $('#create_time').val(obj.create_time);
                             $('#phone').val(obj.phone);  
                               if(obj.complain_annex.length>0){ 
                                 var imagehtml = "";
                                 $("#complain_annex").html('');
                                for(var i=0;i<obj.complain_annex.length;i++){
                                     imagehtml += "<img style='margin-right:5px' width='100px' height='100px' src="+obj.complain_annex[i]+">";
                                } 
                            }else{
                                 $('#complain_annex').html('未设置'); 
                            }
                            $("#complain_annex").append(imagehtml); 
                             $('#object_type').val(obj.object_type); 
                            var userDetailModal = layer.open({
                                title:'投诉订单详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px']
                                ,content: $('#hotelOrderInfo')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }


                    }
                })
            }
            else if(obj.event === 'solveds'){  
                layer.confirm('确认已处理吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('OrderComplains/solved')}",
                        type: 'post',
                        dataType: 'json',
                        data: {complain_status:data.complain_status},
                        success: function(msg){
                            layer.close(loading);
                            if (msg === "1") {
                           layer.msg('已处理', {icon: 1, time: 1000},function(){
                                        window.location.reload();
                                    });
                            }else{
                                layer.msg('处理失败',{icon:2,time:1000});
                            }
                        }
                    })

                });
           
            }else if(obj.event === 'solved'){
                layer.confirm('该订单投诉结果',{
                    btn: ['已解决', '未解决', '取消']
                    ,yes:function(){
                        var loading = layer.load(1, {
                            shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });
                        $.ajax({
                            url: "{:url('OrderComplains/solved')}",
                            type: 'post',
                            dataType: 'json',
                            data: {complain_status:1,order_sn:data.order_sn},
                            success: function(msg){
                                layer.close(loading);
                                if (msg === 1) {
                                    layer.msg('已解决', {icon: 1, time: 1000},function(){
                                        window.location.reload();
                                    });
                                }else{
                                    layer.msg('系统错误',{icon:2,time:1000});
                                }
                            }
                        });
                    }
                    ,btn2:function(){
                        var loading = layer.load(1, {
                            shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });
                        $.ajax({
                            url: "{:url('OrderComplains/solved')}",
                            type: 'post',
                            dataType: 'json',
                            data: {complain_status:2,order_sn:data.order_sn},
                            success: function (msg) {
                                layer.close(loading);
                                if (msg === 1) {
                                    layer.msg('未解决', {icon: 1, time: 1000},function(){
                                        window.location.reload();
                                    });
                                } else {
                                    layer.close(loading);
                                    layer.msg('系统错误', {icon: 2, time: 1000});
                                }
                            }
                        })
                    }
                    ,btn3:function(){
                        layer.closeAll();
                    }
                });
            }

        });

        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Merchant/guideAdd')}";
            },
            searchUserButton:function(){
                var order_sn     = $('#order_sn').val();
                var order_status = $("#order_status_").val();
                var selectdate   = $("#selectdate").val();

                table.reload('test-table-operate', {
                    where: {
                        order_sn:order_sn,
                        order_status:order_status,
                        selectdate:selectdate
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

    //格式化时间函数
    function Format(datetime,fmt) {
        if (parseInt(datetime)==datetime) {
            if (datetime.length==10) {
                datetime=parseInt(datetime)*1000;
            } else if(datetime.length==13) {
                datetime=parseInt(datetime);
            }
        }
        datetime=new Date(datetime);
        var o = {
            "M+" : datetime.getMonth()+1,                 //月份
            "d+" : datetime.getDate(),                    //日
            "h+" : datetime.getHours(),                   //小时
            "m+" : datetime.getMinutes(),                 //分
            "s+" : datetime.getSeconds(),                 //秒
            "q+" : Math.floor((datetime.getMonth()+3)/3), //季度
            "S"  : datetime.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (datetime.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    }

</script>


</body>
</html>